var UI = {
    init: function () {
        function b(e) {
            var t = e.attr("menu");
            if (!e.hasClass("disabled")) switch (t) {
                case "save":
                case "renamefile":
                    break;
                case "openStation":
                    $("#openFile").trigger("click"),
                        $("#openFile").change(function (e) {
                            $(this).val()
                        });
                    break;
                case "download":
                    var n = $("#export_dialog"),
                        o = .25 * $(window).width(),
                        i = .2 * $(window).height();
                    n.css({
                        position: "absolute",
                        left: o + "px",
                        top: i + "px"
                    }),
                        $("#exportOkButtion").unbind("click").bind("click",
                            function (e) {
                                1 == document.getElementById("export_png").checked ? exportStation() : 1 == document.getElementById("export_exl").checked ? exportLsbExl() : 1 == document.getElementById("export_json").checked && exportData(),
                                    n.modal("hide")
                            }),
                        n.modal("show");
                    break;
                case "close":
                    break;
                case "cfgds":
                    "开始双动道岔配置" == e.find("a").text() ? (e.find("a").text("停止双动道岔配置"), UI.showFixTipMessage("正在配置双道岔，恢复操作请点击菜单联锁表->停止道岔配置项", !1), Designer.op.setOpMode("CFGSMode")) : (e.find("a").text("开始双动道岔配置"), UI.showFixTipMessage("退出双动道岔配置，恢复正常操作", !0), Designer.op.setOpMode("OPMode"));
                    break;
                case "lsbdatacheck":
                    UI.deviceDataTableCFG(),
                        $("#lsbdatacheck").modal("show");
                    break;
                case "cfgps":
                    lsb.findDeviceProperty($("#designer_canvas").children("canvas")[0]);
                    break;
                case "buildlsb":
                    lsb.buildLSB();
                    break;
                case "pathReview":
                    "查看信号始端进路" == e.find("a").text() ? (e.find("a").text("退出查看信号始端进路"), Designer.op.setOpMode("PATH_REVIEW_Mode")) : (e.find("a").text("查看信号始端进路"), Designer.op.setOpMode("OPMode"));
                    break;
                case "editlsbtable":
                    "打开联锁表" == e.find("a").text() ? (e.find("a").text("关闭联锁表"), UI.displayLSB(!0)) : (e.find("a").text("打开联锁表"), UI.displayLSB(!1));
                    break;
                case "lk_button":
                    lk.setLKButton();
                    break;
                case "lk_button_show":
                    Designer.op.buttonShowFlag = !0,
                        Designer.op.refreshElements();
                    break;
                case "lk_button_hide":
                    Designer.op.buttonShowFlag = !1,
                        Designer.op.refreshElements();
                    break;
                case "lk_jyj_build":
                    Model.buildJYJ();
                    break;
                case "lk_jyj_show":
                    Designer.op.jyjShowFlag = !0,
                        Designer.op.refreshElements();
                    break;
                case "lk_jyj_hide":
                    Designer.op.jyjShowFlag = !1,
                        Designer.op.refreshElements();
                    break;
                case "fullscreean":
                    UI.fullScrean();
                    break;
                case "test":
                    break;
                case "lktest":
                    Designer.op.scratShape();
                    var a = [];
                    a[0] = Model.fileInfo,
                        a[1] = Model.elements,
                        a[2] = Model.fhSwitchTable,
                        a[3] = Model.ddSwitchTable,
                        a[4] = lsb.routateTable,
                        a[5] = lsb.lsbStringData,
                        localStorage.setItem("currentStation", JSON.stringify(a)),
                        document.location.href = encodeURI("/hmi");
                    break;
                case "hotkey":
                    $("#hotkey_list").modal("show");
                    break;
                case "getting_started":
                    break;
                case "feedback":
                    break;
                case "tipinfotoggle":
                    Designer.op.tipInfo ? Designer.op.tipInfo = !1 : Designer.op.tipInfo = !0
            }
        }

        function exportData() {
            $("#saveFile").attr("accept", "text/plain"),
                $("#saveFile").change(function (e) {
                    $(this).val()
                }),
                $("#saveFile").trigger("click")
        }

        function exportStation() {
            $("#saveFile").attr("accept", "image/png"),
                $("#saveFile").change(function (e) {
                    var t = $(this).val(),
                        n = require("fs");
                    UI.preViewPanel(!1);
                    var i = document.getElementById("preView_canvas"),
                        a = i.toDataURL("image/png").replace(/^data:image\/\w+;base64,/, ""),
                        s = new Buffer(a, "base64");
                    n.writeFile(t, s,
                        function (e) {
                        })
                }),
                $("#saveFile").trigger("click")
        }

        function exportLsbExl() {
            $("#saveFile").attr("accept", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
                $("#saveFile").change(function (evt) {
                    var path = $(this).val(),
                        fs = require("fs"),
                        xlsx = require("node-xlsx"),
                        txt = "";
                    txt += "  [{'name':'联锁表', 'data':[  ",
                        txt += "    [",
                        txt += "     {'value':'','formatCode':'General', 'colSpan':8, 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'},'fontColor':'ff0000'},",
                        txt += "     {'value':'信号机','formatCode':'General', 'colSpan':3, 'hAlign':'center', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'},'fontColor':'ff0000'},",
                        txt += "      {'value':'','formatCode':'General', 'colSpan':3, 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'}},",
                        txt += "      {'value':'迎面进路','formatCode':'General', 'colSpan':2, 'hAlign':'center', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'},'fontColor':'ff0000'},",
                        txt += "      {'value':'','formatCode':'General', 'colSpan':1, 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'}}",
                        txt += "   ], ",
                        txt += "    [",
                        txt += "      {'value':'方向','formatCode':'General', 'colSpan':3, 'hAlign':'center', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'},'fontColor':'ff0000'},",
                        txt += "      {'value':'进路号码','formatCode':'General', 'colSpan':1, 'hAlign':'center', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'},'fontColor':'ff0000'},",
                        txt += "      {'value':'进路','formatCode':'General', 'colSpan':1, 'hAlign':'center', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'},'fontColor':'ff0000'},",
                        txt += "      {'value':'进路方式','formatCode':'General', 'colSpan':1, 'hAlign':'center', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'},'fontColor':'ff0000'},",
                        txt += "     {'value':'进路按钮','formatCode':'General', 'colSpan':1, 'hAlign':'center', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'},'fontColor':'ff0000'},",
                        txt += "     {'value':'关键道岔','formatCode':'General', 'colSpan':1, 'hAlign':'center', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'},'fontColor':'ff0000'},",
                        txt += "      {'value':'名称','formatCode':'General', 'colSpan':1, 'hAlign':'center', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'},'fontColor':'ff0000'},",
                        txt += "      {'value':'显示','formatCode':'General', 'colSpan':1, 'hAlign':'center', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'},'fontColor':'ff0000'},",
                        txt += "      {'value':'表示器','formatCode':'General', 'colSpan':1, 'hAlign':'center', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'},'fontColor':'ff0000'},",
                        txt += "      {'value':'道岔','formatCode':'General', 'colSpan':1, 'hAlign':'center', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'},'fontColor':'ff0000'},",
                        txt += "      {'value':'敌对信号','formatCode':'General', 'colSpan':1, 'hAlign':'center', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'},'fontColor':'ff0000'},",
                        txt += "      {'value':'轨道区段','formatCode':'General', 'colSpan':1, 'hAlign':'center', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'},'fontColor':'ff0000'},",
                        txt += "      {'value':'列车','formatCode':'General', 'colSpan':1, 'hAlign':'center', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'},'fontColor':'ff0000'},",
                        txt += "      {'value':'调车','formatCode':'General', 'colSpan':1, 'hAlign':'center', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'},'fontColor':'ff0000'},",
                        txt += "      {'value':'其它联锁','formatCode':'General', 'colSpan':1, 'hAlign':'center', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'},'fontColor':'ff0000'}",
                        txt += "    ],  ";
                    for (var i = 0; i < lsb.lsbStringData.length; i++) txt += "     [",
                        txt += "     {'value':'",
                        txt += lsb.lsbStringData[i].aspect1,
                        txt += "','formatCode':'General', 'colSpan':1, 'autoWidth':'true', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'}},",
                        txt += "     {'value':'",
                        txt += lsb.lsbStringData[i].aspect2,
                        txt += "','formatCode':'General', 'colSpan':1, 'autoWidth':'true', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'}},",
                        txt += "     {'value':'",
                        txt += lsb.lsbStringData[i].aspect3,
                        txt += "','formatCode':'General', 'colSpan':1, 'autoWidth':'true', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'}},",
                        txt += "     {'value':'",
                        txt += lsb.lsbStringData[i].number,
                        txt += "','formatCode':'General', 'colSpan':1, 'autoWidth':'true', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'}},",
                        txt += "     {'value':'",
                        txt += lsb.lsbStringData[i].path,
                        txt += "','formatCode':'General', 'colSpan':1, 'autoWidth':'true', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'}},",
                        txt += "     {'value':'",
                        txt += lsb.lsbStringData[i].routeType,
                        txt += "','formatCode':'General', 'colSpan':1, 'autoWidth':'true', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'}},",
                        txt += "     {'value':'",
                        txt += lsb.lsbStringData[i].buttons,
                        txt += "','formatCode':'General', 'colSpan':1, 'autoWidth':'true', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'}},",
                        txt += "     {'value':'",
                        txt += lsb.lsbStringData[i].keySwitch,
                        txt += "','formatCode':'General', 'colSpan':1, 'autoWidth':'true', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'}},",
                        txt += "     {'value':'",
                        txt += lsb.lsbStringData[i].signalName,
                        txt += "','formatCode':'General', 'colSpan':1, 'autoWidth':'true', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'}},",
                        txt += "     {'value':'",
                        txt += lsb.lsbStringData[i].signalDisplay,
                        txt += "','formatCode':'General', 'colSpan':1, 'autoWidth':'true', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'}},",
                        txt += "     {'value':'",
                        txt += lsb.lsbStringData[i].signalBSQ,
                        txt += "','formatCode':'General', 'colSpan':1, 'autoWidth':'true', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'}},",
                        txt += "     {'value':'",
                        txt += lsb.lsbStringData[i].switches,
                        txt += "','formatCode':'General', 'colSpan':1, 'autoWidth':'true', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'}},",
                        txt += "     {'value':'",
                        txt += lsb.lsbStringData[i].conflictSignal,
                        txt += "','formatCode':'General', 'colSpan':1, 'autoWidth':'true', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'}},",
                        txt += "     {'value':'",
                        txt += lsb.lsbStringData[i].tracks,
                        txt += "','formatCode':'General', 'colSpan':1, 'autoWidth':'true', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'}},",
                        txt += "     {'value':'",
                        txt += lsb.lsbStringData[i].lieFC,
                        txt += "','formatCode':'General', 'colSpan':1, 'autoWidth':'true', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'}},",
                        txt += "     {'value':'",
                        txt += lsb.lsbStringData[i].diaoFC,
                        txt += "','formatCode':'General', 'colSpan':1, 'autoWidth':'true', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'}},",
                        txt += "     {'value':'",
                        txt += "",
                        txt += "','formatCode':'General', 'colSpan':1, 'autoWidth':'true', 'borders':{'left':'000000', 'right':'000000', 'top':'000000', 'bottom':'000000'}},",
                        txt += "   ],";
                    txt += " ]}] ";
                    var buffer = xlsx.build({
                        worksheets: eval(txt)
                    });
                    fs.writeFileSync(path, buffer, "binary",
                        function (e) {
                        })
                }),
                $("#saveFile").trigger("click")
        }

        $(".tiptest").tooltip(),
            $(".panelclose").bind("click",
                function (e) {
                    $(".panel").hide()
                }),
            $(".menuitem").bind("click",
                function (e) {
                    var t = $(this);
                    b(t)
                });
        var seletedID;
        $("#designer_canvas").bind("dblclick",
            function (e) {
                seletedID = Designer.op.getCurrentSelectedID(),
                    Designer.op.cancelSelected(),
                -1 != seletedID && (UI.cfgPanelDisplay(seletedID, e), e.stopPropagation())
            }),
            $("#signalCancelButton").bind("click",
                function (e) {
                    var t = $("#signalcfgpanel");
                    t.hide()
                }),
            $("#signalOKButton").bind("click",
                function (e) {
                    var t = $("#signalcfgpanel"),
                        n = Model.getNodeByID(seletedID),
                        o = "";
                    if (-1 == n) {
                        o = "<strong>错误:</strong><span>图形已被删除，请关闭当前窗口重新选择！</span>";
                        var i = $("#signalerrormsg");
                        return i.html(o),
                            void i.show()
                    }
                    var a = t.find("#signalname").val();
                    if ("" == a && (o += "<strong>错误:</strong><span>信号机名为空或填写错误，请确认!</span><br />"), Model.existedByName(n.category, a, seletedID) && (o += "<strong>错误:</strong><span>信号机名称已经存在，请确认!</span><br />"), a = t.find("#signalthroat").val(), "" == a && (o += "<strong>错误:</strong><span>咽喉区为空或填写错误，请确认!</span><br />"), "LIE" == n.type.match("LIE")) {
                        var s = [];
                        document.getElementById("u").checked && s.push("U"),
                        document.getElementById("uu").checked && s.push("UU"),
                        document.getElementById("lu").checked && s.push("LU"),
                        document.getElementById("l").checked && s.push("L"),
                        document.getElementById("ll").checked && s.push("LL"),
                        document.getElementById("usu").checked && s.push("USU"),
                        document.getElementById("yb").checked && s.push("YB"),
                        document.getElementById("db").checked && s.push("DB"),
                        0 == s.length && (o += "<strong>错误:</strong><span>信号机颜色不能为空，请确认!</span><br />");
                        var r = "";
                        document.getElementById("jz").checked ? r = "JZ" : document.getElementById("cz").checked ? r = "CZ" : document.getElementById("czd").checked ? r = "CZD" : document.getElementById("jl").checked ? r = "JL" : document.getElementById("fs").checked ? r = "FS" : document.getElementById("tf").checked && (r = "TF"),
                        "" == r && (o += "<strong>错误:</strong><span>信号机类型不能为空，请选择!</span><br />");
                        var l = [];
                        document.getElementById("lButton").checked && l.push("LBUTTON"),
                        document.getElementById("dButton").checked && l.push("DBUTTON"),
                        document.getElementById("dzButton").checked && l.push("DZBUTTON"),
                        document.getElementById("tgButton").checked && l.push("TGBUTTON"),
                        document.getElementById("ydButton").checked && l.push("YDBUTTON");
                        var h = "";
                        document.getElementById("wufangxiang").checked ? h = "WUFANGXIANG" : document.getElementById("shuangfangxiang").checked ? h = "SHUANGFANGXIANG" : document.getElementById("sanfangxiang").checked && (h = "SANFANGXIANG")
                    }
                    if ("" != o) {
                        $("#signalcfgmsg").hide();
                        var i = $("#signalerrormsg");
                        return i.html(o),
                            void i.show()
                    }
                    if (n.name = t.find("#signalname").val(), n.throat = t.find("#signalthroat").val(), n.qianNode = Model.getIDByIndex(Model.getNodeByName(t.find("#qiannode").val())), n.houNode = Model.getIDByIndex(Model.getNodeByName(t.find("#hounode").val())), "LIE" == n.type.match("LIE")) {
                        n.signalType = r,
                            n.fxbsq = h,
                            n.xianshi.splice(0, n.xianshi.length);
                        for (var c = 0; c < s.length; c++) n.xianshi[c] = s[c];
                        n.button.splice(0, n.button.length);
                        for (var c = 0; c < l.length; c++) n.button[c] = l[c];
                        n.fangmian = t.find("#fangmiancontainer").find("input").val()
                    } else document.getElementById("lzButton").checked ? (n.button[0] = "LZBUTTON", n.button[1] = "DBUTTON") : document.getElementById("dlButton").checked && (n.button[0] = "DLBUTTON");
                    t.hide()
                }),
            $("#switchCancelButton").bind("click",
                function (e) {
                    var t = $("#switchcfgpanel");
                    t.hide()
                }),
            $("#switchOKButton").bind("click",
                function (e) {
                    var t = $("#switchcfgpanel"),
                        n = t.find("#switchname").val(),
                        o = "";
                    if (isNaN(n) ? o += "<strong>错误:</strong><span>道岔名是数字，请正确填写！</span><br />" : (n > 200 && (o += "<strong>错误:</strong><span>道岔名小于200，请修改!</span><br />"), Model.existedByName("SWITCH", n, seletedID) && (o += "<strong>错误:</strong><span>道岔名已经存在，请确认!</span><br />"), "" == n && (o += "<strong>错误:</strong><span>道岔名为空或填写错误，请确认!</span><br />")), n = t.find("#switchthroat").val(), "" == n && (o += "<strong>错误:</strong><span>咽喉区为空或填写错误，请确认!</span><br />"), n = t.find("#switchangel").val(), isNaN(n) ? o += "<strong>错误:</strong><span>道岔开口大小是数字，请正确填写！</span><br />" : (5 > n || n > 85) && (o += "<strong>错误:</strong><span>道岔开口大小5～85之间，请正确填写！</span><br />"), "" == t.find("#switchtrack").val() && (o += "<strong>错误:</strong><span>道岔区段不能为空，请正确填写！</span><br />"), "" != o) {
                        $("#switchcfgmsg").hide();
                        var i = $("#switcherrormsg");
                        return i.html(o),
                            void i.show()
                    }
                    var a = Model.getNodeByID(seletedID);
                    if (-1 == a) {
                        o = "<strong>错误:</strong><span>图形已被删除，请关闭当前窗口重新选择！</span>";
                        var i = $("#switcherrormsg");
                        return i.html(o),
                            void i.show()
                    }
                    a.name = t.find("#switchname").val(),
                        a.track = t.find("#switchtrack").val(),
                        a.throat = t.find("#switchthroat").val(),
                        a.qianNode = Model.getIDByIndex(Model.getNodeByName(t.find("#preswitchnode").val())),
                        a.wanNode = Model.getIDByIndex(Model.getNodeByName(t.find("#aftanoswitchnode").val())),
                        a.zhiNode = Model.getIDByIndex(Model.getNodeByName(t.find("#aftzhiswitchnode").val())),
                        a.chaXinAngel = t.find("#switchangel").val(),
                        1 == document.getElementById("wzxf1").checked ? a.reverse = "default" : a.reverse = "reverse",
                        Designer.op.changChaWanAngel(seletedID, a.chaXinAngel),
                        t.hide()
                }),
            $("#trackCancelButton").bind("click",
                function (e) {
                    var t = $("#trackcfgpanel");
                    t.hide()
                }),
            $("#trackOKButton").bind("click",
                function (e) {
                    var t = $("#trackcfgpanel"),
                        n = Model.getNodeByID(seletedID),
                        o = "";
                    if (-1 == n) {
                        o = "<strong>错误:</strong><span>图形已被删除，请关闭当前窗口重新选择！</span>";
                        var i = $("#signalerrormsg");
                        return i.html(o),
                            void i.show()
                    }
                    var a = t.find("#trackname").val();
                    if ("" == a && (o += "<strong>错误:</strong><span> 区段名为空或填写错误，请确认!</span><br />"), Model.existedByName(n.category, a, seletedID) && (o += "<strong>错误:</strong><span>区段名称已经存在，请确认!</span><br />"), a = t.find("#trackthroat").val(), "" == a && (o += "<strong>错误:</strong><span>咽喉区为空或填写错误，请确认!</span><br />"), "" != o) {
                        $("#trackcfgmsg").hide();
                        var i = $("#trackerrormsg");
                        return i.html(o),
                            void i.show()
                    }
                    n.name = t.find("#trackname").val(),
                        n.throat = t.find("#trackthroat").val(),
                        n.qianNode = Model.getIDByIndex(Model.getNodeByName(t.find("#qiannode").val())),
                        n.houNode = Model.getIDByIndex(Model.getNodeByName(t.find("#hounode").val()));
                    var s = "";
                    document.getElementById("gd").checked ? s = "GD" : document.getElementById("wcqd").checked ? s = "WCQD" : document.getElementById("dcqd").checked && (s = "DCQD"),
                        n.trackType = s,
                        t.hide()
                }),
            $("#buttonCancelButton").bind("click",
                function (e) {
                    var t = $("#buttoncfgpanel");
                    t.hide()
                }),
            $("#buttonOKButton").bind("click",
                function (e) {
                    var t = $("#buttoncfgpanel"),
                        n = Model.getNodeByID(seletedID),
                        o = "";
                    if (-1 == n) {
                        o = "<strong>错误:</strong><span>图形已被删除，请关闭当前窗口重新选择！</span>";
                        var i = $("#buttonerrormsg");
                        return i.html(o),
                            void i.show()
                    }
                    var a = t.find("#buttonthroat").val();
                    "" == a && (o += "<strong>错误:</strong><span>咽喉区为空或填写错误，请确认!</span><br />");
                    var a = t.find("#buttonname").val();
                    if ("" == a && (o += "<strong>错误:</strong><span>按钮名为空或填写错误，请确认!</span><br />"), Model.existedByName(n.category, a, seletedID) && (o += "<strong>错误:</strong><span>按钮名已经存在，请确认!</span><br />"), "" != o) {
                        $("#buttoncfgmsg").hide();
                        var i = $("#buttonerrormsg");
                        return i.html(o),
                            void i.show()
                    }
                    n.name = t.find("#buttonname").val(),
                        n.throat = t.find("#buttonthroat").val(),
                        n.qianNode = Model.getIDByIndex(Model.getNodeByName(t.find("#qiannode").val())),
                        n.houNode = Model.getIDByIndex(Model.getNodeByName(t.find("#hounode").val()));
                    var s = "";
                    document.getElementById("bgbutton").checked ? s = "BGBUTTON" : document.getElementById("yxbutton").checked && (s = "YXBUTTON"),
                        n.buttonType = s,
                        t.hide()
                }),
            $("#textCancelButton").bind("click",
                function (e) {
                    var t = $("#textcfgpanel");
                    t.hide()
                }),
            $("#textOKButton").bind("click",
                function (e) {
                    var t = $("#textcfgpanel"),
                        n = t.find("#fontsize").val(),
                        o = "";
                    if (isNaN(n) ? o += "<strong>错误:</strong><span>字符大小是数字，请正确填写！</span><br />" : (n > 200 && (o += "<strong>错误:</strong><span>字符应小于80，请修改!</span><br />"), "" == n && (o += "<strong>错误:</strong><span>字符大小为空或填写错误，请确认!</span><br />")), n = t.find("#switchthroat").val(), "" == n && (o += "<strong>错误:</strong><span>咽喉区为空或填写错误，请确认!</span><br />"), "" == t.find("#text").val() && (o += "<strong>错误:</strong><span>字符不能为空，请正确填写！</span><br />"), "" != o) {
                        var i = $("#texterrormsg");
                        return i.html(o),
                            void i.show()
                    }
                    var a = Model.getNodeByID(seletedID);
                    if (-1 == a) {
                        o = "<strong>错误:</strong><span>图形已被删除，请关闭当前窗口重新选择！</span>";
                        var i = $("#texterrormsg");
                        return i.html(o),
                            void i.show()
                    }
                    a.name = t.find("#text").val(),
                        a.fontStytle.size = t.find("#fontsize").val(),
                        t.hide()
                }),
            $("#lsbdatacheckOKButton").bind("click",
                function (e) {
                    $("#lsbdatacheck").find("tr").each(function () {
                        var e = $(this),
                            t = e.attr("id");
                        "spswitch" != t && (t = Model.getIndexByID(t), -1 != t && e.find("td").each(function () {
                            var e = $(this),
                                n = e.attr("property"),
                                o = e.text();
                            if ("otherSwitch" == n) {
                                var i = Model.getNodeByName(o);
                                -1 != i && (Model.elements[t].otherSwitch = Model.elements[i].id)
                            } else if ("track" == n) Model.elements[t].track = o;
                            else if ("qianNode" == n) {
                                var i = Model.getNodeByName(o);
                                -1 != i && (Model.elements[t].qianNode = Model.elements[i].id)
                            } else if ("houNode" == n) {
                                var i = Model.getNodeByName(o);
                                -1 != i && (Model.elements[t].houNode = Model.elements[i].id)
                            } else if ("zhiNode" == n) {
                                var i = Model.getNodeByName(o);
                                -1 != i && (Model.elements[t].zhiNode = Model.elements[i].id)
                            } else if ("wanNode" == n) {
                                var i = Model.getNodeByName(o);
                                -1 != i && (Model.elements[t].wanNode = Model.elements[i].id)
                            } else if ("throat" == n) Model.elements[t].throat = o;
                            else if ("otherSignal" == n) {
                                var i = Model.getNodeByName(o);
                                -1 != i && (Model.elements[t].otherSignal = Model.elements[i].id)
                            } else if ("otherdbcross" == n) {
                                var i = Model.getNodeByName(o);
                                -1 != i && (Model.elements[t].otherDoubleCrossover = Model.elements[i].id)
                            }
                        }))
                    });
                    var t = {
                            zdc: "",
                            fhdc: ""
                        },
                        n = {
                            zdc: "",
                            dddc: ""
                        },
                        o = document.getElementById("spstable");
                    for (Model.ddSwitchTable.splice(0, Model.ddSwitchTable.length), Model.fhSwitchTable.splice(0, Model.fhSwitchTable.length), j = 0; j < o.rows.length; j++) {
                        if (o.rows[j].cells[1].innerText && o.rows[j].cells[2].innerText) {
                            var i = Utils.copy(t);
                            i.zdc = o.rows[j].cells[1].innerText,
                                i.fhdc = o.rows[j].cells[2].innerText,
                                Model.fhSwitchTable.push(i)
                        }
                        if (o.rows[j].cells[3].innerText && o.rows[j].cells[4].innerText) {
                            var a = Utils.copy(n);
                            a.zdc = o.rows[j].cells[3].innerText,
                                a.dddc = o.rows[j].cells[4].innerText,
                                Model.ddSwitchTable.push(a)
                        }
                    }
                    $("#lsbdatacheck").find("td").unbind("dblclick"),
                        $("#lsbdatacheck").modal("hide")
                })
    },
    isSaving: !1,
    showAlertDlg: function (e) {
        var t = $("#bootbox"),
            n = $("#bootbox_dlg");
        n.css({
            position: "absolute",
            left: $(window).height() / 2 + "px",
            top: $(window).width() / 5 + "px",
            height: $(window).height() / 5 + "px",
            width: $(window).width() / 3 + "px",
            margin: "0px"
        }),
            t.find("span").text(e),
            t.modal("show")
    },
    preViewPanel: function (e) {
        function d(t, n) {
            var o = n.left,
                i = n.top,
                a = h / (n.right - n.left + 200),
                s = c / (n.bottom - n.top + 200),
                r = 1;
            r = a > s ? s : a,
            r > 1 && (r = 1);
            for (var l = 0; l < t.length; l++) e && t[l].renderShape(r),
                t[l].MoveOffset(-o * r, -i * r);
            var p = UI.getShapesScope(t);
            o = 0,
                i = 0,
            c - (p.bottom - p.top) > 0 && (i = (c - (p.bottom - p.top)) / 2),
            h - (p.right - p.left) > 0 && (o = (h - (p.right - p.left)) / 2);
            for (var l = 0; l < t.length; l++) t[l].MoveOffset(o, i)
        }

        function f(e, t) {
            for (var n = 0; n < e.length; n++) e[n].showShape(t)
        }

        function g(e, t, n) {
            var o = Model.page.backgroundColor,
                i = 0,
                a = "242,242,242",
                s = "229,229,229",
                r = e.getContext("2d");
            r.save(),
                r.clearRect(0, 0, n, t);
            var l = n,
                h = t;
            r.fillStyle = "rgb(" + o + ")",
                r.beginPath(),
                r.rect(i, i, l, h),
                r.fill();
            var c = Math.round(Model.page.gridSize);
            if (10 > c && (c = 10), Model.page.showGrid) {
                r.translate(i, i),
                    r.lineWidth = 1;
                for (var p = .5,
                         d = 0; h > p;) d % 4 == 0 ? r.strokeStyle = "rgb(" + s + ")" : r.strokeStyle = "rgb(" + a + ")",
                    r.beginPath(),
                    r.moveTo(0, p),
                    r.lineTo(l, p),
                    p += c,
                    d++,
                    r.stroke();
                for (p = .5, d = 0; l >= p;) d % 4 == 0 ? r.strokeStyle = "rgb(" + s + ")" : r.strokeStyle = "rgb(" + a + ")",
                    r.beginPath(),
                    r.moveTo(p, 0),
                    r.lineTo(p, h),
                    p += c,
                    d++,
                    r.stroke()
            }
            r.restore()
        }

        var t = $("#fullScreen"),
            n = $(window).width(),
            o = $(window).height(),
            i = Model.getShapescopy();
        if (1 != Designer.op.zoomCount) for (var a = 1 / Designer.op.zoomCount,
                                                 s = 0; s < i.length; s++) i[s].renderShape(a);
        var h, c, r = UI.getShapesScope(i),
            l = $("#preView_canvas");
        e ? (c = o - 30, h = n - 40) : (c = r.bottom - r.top - 30, h = r.right - r.left - 40),
            t.css({
                position: "absolute",
                left: "0px",
                top: "0px",
                height: o + "px",
                width: n + "px",
                margin: "0px",
                padding: "0px"
            });
        var p = $("#fullscreendialog");
        p.css({
            position: "absolute",
            left: "3px",
            top: "3px",
            height: o - 15 + "px",
            width: n - 18 + "px",
            margin: "0px"
        }),
            l.attr("height", c),
            l.attr("width", h),
            g(document.getElementById("preView_canvas"), c - 15, h - 15),
            d(i, r),
            f(i, document.getElementById("preView_canvas"))
    },
    fullScrean: function () {
        var e = $("#fullScreen");
        UI.preViewPanel(!0),
            e.modal("show");
        var t = $(document.getElementById("previewTipMsg"));
        t.css({
            position: "absolute",
            left: $(window).width() / 2 + "px",
            top: "20px"
        }),
            t.show(),
            e.unbind("keydown.preview").bind("keydown.preview",
                function (t) {
                    27 == t.keyCode && e.modal("hide")
                })
    },
    getShapesScope: function (e) {
        function o(e) {
            e.x < t.left && (t.left = e.x),
            e.y < t.top && (t.top = e.y),
            e.x > t.right && (t.right = e.x),
            e.y > t.bottom && (t.bottom = e.y)
        }

        for (var t = {
                top: 1e5,
                left: 1e5,
                bottom: -10,
                right: -10
            },
                 n = 1; n < e.length; n++)"SWITCH" == e[n].category ? (o(e[n].component.chaJian[0]), o(e[n].component.chaZhi[1]), o(e[n].component.chaWan[1])) : "SIGNAL" == e[n].category ? (o(e[n].component.base[0]), o(e[n].component.base[1])) : "TRACK" == e[n].category ? (o(e[n].component.point[0]), o(e[n].component.point[1])) : "LIANXI" == e[n].category ? o(e[n].component.point[0]) : "TUO_GUI_QI" == e[n].category ? o(e[n].component.point[0]) : "QIN_XIAN" == e[n].category ? o(e[n].component.point[0]) : "STUB_END_SIDING" == e[n].category ? (o(e[n].component.point[0]), o(e[n].component.point[1])) : "64D" == e[n].category ? (o(e[n].component.point[0]), o(e[n].component.point[6])) : "BUTTON" == e[n].category ? o(e[n].component.point[0]) : "TEXT" == e[n].category && o(e[n].component.point[0]);
        return t
    },
    displayLSB: function (e) {
        function p(e) {
            for (var t = [], n = 0; n < l.length; n++) l[n].group == e && t.push(l[n]);
            return t
        }

        function d(e, t, n, o) {
            o[e][t] = n
        }

        function f(e, t) {
            var n = $("#lsbtabledata");
            n.empty();
            var o = "";
            o += "<table class='table table-bordered table-condensed  table-hover'> <tbody>",
                o += "</tbody></table>",
                n.html(o);
            for (var i = 0; i < t.length; i++) {
                var a = "";
                o = "",
                    o += "<tr align='center' index='" + i + "'>",
                    o += "<td class='cellwth1' tp='aspect1'>" + t[i].aspect1 + "</td>",
                    o += "<td class='cellwth1' tp='aspect2'>" + t[i].aspect2 + "</td>",
                    o += "<td class='cellwth1' tp='aspect3'>" + t[i].aspect3 + "</td>",
                    o += "<td class='cellwth1' tp='number'>" + t[i].number + "</td>",
                    o += "<td  class='cellwth2' tp='path'>" + t[i].path + "</td>",
                    o += "<td class='cellwth1' tp='routeType'>" + t[i].routeType + "</td>";
                var a = "";
                a = t[i].buttons,
                    o += "<td class='cellwth2' tp='buttons'>" + a + "</td>",
                    a = t[i].keySwitch,
                    o += "<td class='cellwth25' tp='keySwitch'>" + a + "</td>",
                    a = t[i].signalName,
                    o += "<td class='cellwth1' tp='signalName'>" + a + "</td>",
                    a = t[i].signalDisplay,
                    o += "<td class='cellwth2' tp='signalDisplay'>" + a + "</td>",
                    a = t[i].signalBSQ,
                    o += "<td class='cellwth15' tp='signalBSQ'>" + a + "</td>",
                    a = t[i].switches,
                    o += "<td class='cellwth5' tp='switches'>" + a + "</td>",
                    a = t[i].conflictSignal,
                    o += "<td class='cellwth4' tp='conflictSignal'>" + a + "</td>",
                    a = t[i].tracks,
                    o += "<td tp='tracks'>" + a + "</td>",
                    a = t[i].lieFC,
                    o += "<td class='cellwth1' tp='lieFC'>" + a + "</td>",
                    a = t[i].diaoFC,
                    o += "<td class='cellwth1' tp='diaoFC'>" + a + "</td>",
                    o += "<td class='cellwth1' tp=''> </td>	",
                    o += "</tr>",
                    e.find("tbody").append(o)
            }
            e.find("tbody").find("td").unbind("click").bind("click",
                function () {
                    var n = $(this).parent(),
                        o = n.attr("index");
                    if (-1 != o) for (var i = t[o].id, a = 0; a < lsb.routateTable.length; a++) if (lsb.routateTable[a].id == i) {
                        o = a;
                        break
                    }
                    var s = $("#lsbcelldata"),
                        r = $(this);
                    if (s.val(r.text()), -1 != i) {
                        for (var a = 0; a < lsb.routateTable.length; a++) lsb.setPathStatu(a, "DEFAULT");
                        lsb.setPathStatu(o, "SELECTED_P");
                        var c, p, l = $("#designer_layout").scrollTop(),
                            h = $("#designer_layout").scrollLeft(),
                            i = lsb.routateTable[o].shapes[0].index;
                        if ("SWITCH" == Model.elements[i].category) c = Model.elements[i].component.chaJian[1];
                        else if ("SIGNAL" == Model.elements[i].category) c = Model.elements[i].component.base[1];
                        else if ("TRACK" == Model.elements[i].category) c = Model.elements[i].component.point[0];
                        else {
                            if ("BUTTON" != Model.elements[i].category) return;
                            c = Model.elements[i].component.point[0]
                        }
                        if (i = lsb.routateTable[o].shapes[lsb.routateTable[o].shapes.length - 1].index, "SWITCH" == Model.elements[i].category) p = Model.elements[i].component.chaJian[1];
                        else if ("SIGNAL" == Model.elements[i].category) p = Model.elements[i].component.base[1];
                        else if ("TRACK" == Model.elements[i].category) p = Model.elements[i].component.point[0];
                        else {
                            if ("BUTTON" != Model.elements[i].category) return;
                            p = Model.elements[i].component.point[0]
                        }
                        c.x < p.x ? (l = c.x, h = c.y) : (l = p.x, h = p.y),
                            e.find("tbody").find("tr").attr("class", "info"),
                            n.attr("class", "success");
                        var f = .15 * $(window).width(),
                            g = .25 * $(window).height();
                        l += Designer.config.pageMargin.toScale(),
                            h += Designer.config.pageMargin.toScale(),
                            $("#designer_layout").scrollLeft(l - f),
                            $("#designer_layout").scrollTop(h - g),
                            Designer.op.refreshElements()
                    }
                    $("#lsbcelldata").unbind("keyup").bind("keyup",
                        function (e) {
                            var n = e || window.event,
                                i = n.keyCode;
                            if (13 == i) {
                                for (var a = r.attr("tp"), l = lsb.routateTable[o].id, h = -1, c = 0; c < t.length; c++) if (t[c].id == l) {
                                    h = c;
                                    break
                                }
                                d(h, a, s.val(), t),
                                    r.text(s.val())
                            }
                        }),
                        $("#setbasicroute").unbind("click").bind("click",
                            function (n) {
                                function i(e, n) {
                                    for (var o = 0; o < e.length; o++) {
                                        var i = $(e[o]).attr("index");
                                        -1 != i && t[i].group == n && (e[o].cells[5].innerText = t[o].routeType)
                                    }
                                }

                                lsb.editBasicRouteFlag(o),
                                    i(e.find("tbody").find("tr"), lsb.routateTable[o].group)
                            }),
                        $("#deleteroute").unbind("click").bind("click",
                            function (e) {
                                n.find("td").text("");
                                for (var i = lsb.routateTable[o].id, a = 0; a < t.length; a++) if (t[a].id == i) {
                                    var s = lsb.getLsbSRIndex(o);
                                    lsb.updateGroupNo(s),
                                        t[a].group = -1;
                                    break
                                }
                            })
                })
        }

        var t = $("#lsbtable_panel");
        if (e) {
            t.hide();
            var s = $("#lsbtableheader");
            s.empty();
            var r = "";
            r += "		  <table class='table table-bordered table-condensed table-striped table-hover ' >",
                r += "			<thead>	",
                r += "				<tr align='center' >",
                r += "					<td colspan='8'></td>	",
                r += "					<td colspan='3'>信号机</td>",
                r += "					<td colspan='3'></td>	",
                r += "					<td colspan='2'>迎面进路</td>",
                r += "					<td></td>		",
                r += "				</tr>",
                r += "				<tr align='center'>",
                r += "					<td class='cellwth1' >方向</td>",
                r += "					<td class='cellwth1' >方向</td>",
                r += "					<td class='cellwth1' >方向</td>",
                r += "					<td class='cellwth1'>进路号码</td>",
                r += "					<td  class='cellwth2' >进路</td>",
                r += "					<td class='cellwth1'>进路方式</td>",
                r += "					<td class='cellwth2'>进路按钮</td>",
                r += "					<td class='cellwth25'>关键道岔</td>",
                r += "					<td class='cellwth1'>名称</td>",
                r += "					<td class='cellwth2'>显示</td>",
                r += "					<td class='cellwth15'>表示器</td>",
                r += "					<td class='cellwth5'>道岔</td>",
                r += "					<td class='cellwth4'>敌对信号</td>",
                r += "					<td >轨道区段</td>",
                r += "					<td class='cellwth1'>列车</td>",
                r += "					<td class='cellwth1'>调车</td>",
                r += "					<td class='cellwth1'>其它联锁</td>	",
                r += "				</tr>",
                r += "			</thead>",
                r += "		</table>",
                s.html(r);
            var l = lsb.getLsbData();
            f(t, l),
                t.show(),
                $("#findString").unbind("keyup").bind("keyup",
                    function (e) {
                        var n = e || window.event,
                            o = n.keyCode;
                        if (13 == o) {
                            for (var i = $("#findString").val(), a = /\s+/, s = i.split(a), r = [], h = [], c = 0; c < s.length; c++)"" != s[c] && r.push(s[c]);
                            for (var c = 0; c < l.length; c++) {
                                for (var p = !1,
                                         d = 0; d < r.length; d++) {
                                    if (-1 == l[c].switches.indexOf(r[d]) && -1 == l[c].conflictSignal.indexOf(r[d]) && -1 == l[c].tracks.indexOf(r[d])) {
                                        p = !1;
                                        break
                                    }
                                    p = !0
                                }
                                p && h.push(l[c])
                            }
                            f(t, h)
                        }
                    }),
                $("#listall").unbind("click").bind("click",
                    function (e) {
                        for (var n = 0,
                                 o = !1; !o;) {
                            var i = lsb.lsbStringData.length;
                            i > n ? -1 == lsb.lsbStringData[n].group ? (lsb.lsbStringData.splice(n, 1), n = 0) : n++ : o = !0
                        }
                        var a = lsb.lsbStringData[0].group,
                            s = [],
                            r = [];
                        for (n = 0; n < lsb.lsbStringData.length; n++) if (a == lsb.lsbStringData[n].group) s.push(lsb.lsbStringData[n]);
                        else {
                            s.length > 0 && "TONG" != s[0].type && s.sort(function (e, t) {
                                return e.routeType - t.routeType
                            });
                            for (var c = 0; c < s.length; c++) r.push(Utils.copy(s[c]));
                            s = [],
                                a = lsb.lsbStringData[n].group,
                                s.push(lsb.lsbStringData[n])
                        }
                        s.length > 0 && r.push(Utils.copy(s[0])),
                            lsb.lsbStringData.splice(0, lsb.lsbStringData.length),
                            lsb.lsbStringData = r,
                            l = lsb.lsbStringData;
                        var p = 1;
                        for (n = 0; n < lsb.lsbStringData.length; n++)"TONG" != lsb.lsbStringData[n].type && (lsb.lsbStringData[n].number = p++);
                        f(t, lsb.lsbStringData),
                            h = 0
                    });
            var h = -1;
            $("#pregroup").unbind("click").bind("click",
                function (e) {
                    for (var o = (lsb.groupCnt, !1), i = []; !o;) h--,
                    0 > h && (h = 0),
                        i = p(h),
                    (i.length > 0 || 0 == h) && (o = !0);
                    f(t, i)
                }),
                $("#nextgroup").unbind("click").bind("click",
                    function (e) {
                        for (var n = lsb.groupCnt,
                                 o = !1,
                                 i = []; !o;) h++,
                        h > n && (h = 0),
                            i = p(h),
                        (i.length > 0 || h >= n) && (o = !0);
                        f(t, i)
                    })
        } else {
            for (var c = 0; c < lsb.routateTable.length; c++) lsb.setPathStatu(c, "DEFAULT");
            t.hide(),
                Designer.op.refreshElements()
        }
    },
    cfgPanelDisplay: function (e, t) {
        switch ($(".panelcfg").hide(), $(".cfgerrormsg").hide(), Model.getCategorByID(e)) {
            case "SWITCH":
                var n = $("#switchcfgpanel"),
                    o = Model.getNodeByID(e);
                n.hide(),
                    $("#switchcfgmsg").show(),
                    n.find(".panel-title").text(o.name + "#道岔参数配置"),
                    n.find("#switchname").val(o.name),
                    n.find("#switchthroat").val(o.throat),
                    n.find("#switchtrack").val(o.track),
                    n.find("#switchangel").val(o.chaXinAngel),
                    n.find("#preswitchnode").val(Model.getNameByID(Model.getIndexByID(o.qianNode))),
                    n.find("#aftanoswitchnode").val(Model.getNameByID(Model.getIndexByID(o.wanNode))),
                    n.find("#aftzhiswitchnode").val(Model.getNameByID(Model.getIndexByID(o.zhiNode))),
                    "default" == o.reverse ? document.getElementById("wzxf1").checked = !0 : document.getElementById("wzxf1").checked = !1;
                var i = Model.elements[e].getRotatePoint(),
                    a = i.x + $("#designer_canvas").offset().left,
                    s = i.y + $("#designer_canvas").offset().top,
                    r = 18;
                $(window).width() - a < n.width() ? (a -= n.width(), a -= r) : a += r,
                    $(window).height() - $("#designer_footer").height() - s < n.height() ? (s -= n.height(), s -= r) : s += r;
                var n = $("#switchcfgpanel");
                n.css({
                    position: "absolute",
                    left: a + "px",
                    top: s + "px"
                }),
                    n.show();
                break;
            case "TRACK":
                var n = $("#trackcfgpanel"),
                    o = Model.getNodeByID(e);
                switch (n.hide(), $("#trackcfgmsg").show(), n.find(".panel-title").text(o.name + "区段参数配置"), n.find("#trackname").val(o.name), n.find("#trackthroat").val(o.throat), n.find("#qiannode").val(Model.getNameByID(Model.getIndexByID(o.qianNode))), n.find("#hounode").val(Model.getNameByID(Model.getIndexByID(o.houNode))), o.trackType) {
                    case "GD":
                        document.getElementById("gd").checked = !0;
                        break;
                    case "WCQD":
                        document.getElementById("wcqd").checked = !0;
                        break;
                    case "DCQD":
                        document.getElementById("dcqd").checked = !0
                }
                var i = Model.elements[e].getControlPoints()[0],
                    a = i.x + $("#designer_canvas").offset().left,
                    s = i.y + $("#designer_canvas").offset().top,
                    r = 25;
                $(window).width() - a < n.width() ? (a -= n.width(), a -= r) : a += r,
                    $(window).height() - $("#designer_header").height() - $("#designer_footer").height() - s < n.height() ? (s -= n.height(), s -= r) : s += r;
                var n = $("#trackcfgpanel");
                n.css({
                    position: "absolute",
                    left: a + "px",
                    top: s + "px"
                }),
                    n.show();
                break;
            case "SIGNAL":
                var n = $("#signalcfgpanel"),
                    o = Model.getNodeByID(e);
                if (n.hide(), $("#signalcfgmsg").show(), n.find(".panel-title").text(o.name + "信号机参数配置"), n.find("#signalname").val(o.name), n.find("#signalthroat").val(o.throat), n.find("#qiannode").val(Model.getNameByID(Model.getIndexByID(o.qianNode))), n.find("#hounode").val(Model.getNameByID(Model.getIndexByID(o.houNode))), "LIE" == o.type.match("LIE")) {
                    var l = $(document.getElementById("fangmiancontainer"));
                    switch (l.hide(), o.signalType) {
                        case "JZ":
                            document.getElementById("jz").checked = !0;
                            var l = $(document.getElementById("fangmiancontainer"));
                            l.find("input")[0].value = "",
                                l.find("input")[0].value = o.fangmian,
                                l.show();
                            break;
                        case "CZ":
                            document.getElementById("cz").checked = !0;
                            break;
                        case "CZD":
                            document.getElementById("czd").checked = !0;
                            break;
                        case "JL":
                            document.getElementById("jl").checked = !0;
                            break;
                        case "FS":
                            document.getElementById("fs").checked = !0;
                            break;
                        case "TF":
                            document.getElementById("tf").checked = !0
                    }
                    var h = $("#liechetype");
                    h.unbind("click").bind("click",
                        function (e) {
                            var t = $(document.getElementById("fangmiancontainer"));
                            1 == h.find("#jz")[0].checked ? t.show() : t.hide()
                        }),
                        document.getElementById("u").checked = !1,
                        document.getElementById("uu").checked = !1,
                        document.getElementById("lu").checked = !1,
                        document.getElementById("l").checked = !1,
                        document.getElementById("ll").checked = !1,
                        document.getElementById("usu").checked = !1,
                        document.getElementById("yb").checked = !1,
                        document.getElementById("db").checked = !1;
                    for (var c = 0; c < o.xianshi.length; c++) switch (o.xianshi[c]) {
                        case "U":
                            document.getElementById("u").checked = !0;
                            break;
                        case "UU":
                            document.getElementById("uu").checked = !0;
                            break;
                        case "LU":
                            document.getElementById("lu").checked = !0;
                            break;
                        case "L":
                            document.getElementById("l").checked = !0;
                            break;
                        case "LL":
                            document.getElementById("ll").checked = !0;
                            break;
                        case "USU":
                            document.getElementById("usu").checked = !0;
                            break;
                        case "YB":
                            document.getElementById("yb").checked = !0;
                            break;
                        case "DB":
                            document.getElementById("db").checked = !0
                    }
                    n.find("#lieche").css({
                        display: "block"
                    }),
                        n.find("#diaoche").css({
                            display: "none"
                        }),
                        document.getElementById("dButton").checked = !1,
                        document.getElementById("lButton").checked = !1,
                        document.getElementById("dzButton").checked = !1,
                        document.getElementById("tgButton").checked = !1,
                        document.getElementById("ydButton").checked = !1;
                    for (var c = 0; c < o.button.length; c++) switch (o.button[c]) {
                        case "LBUTTON":
                            document.getElementById("lButton").checked = !0;
                            break;
                        case "DBUTTON":
                            document.getElementById("dButton").checked = !0;
                            break;
                        case "DZBUTTON":
                            document.getElementById("dzButton").checked = !0;
                            break;
                        case "TGBUTTON":
                            document.getElementById("tgButton").checked = !0;
                            break;
                        case "YDBUTTON":
                            document.getElementById("ydButton").checked = !0
                    }
                    switch (o.fxbsq) {
                        case "WUFANGXIANG":
                            document.getElementById("wufangxiang").checked = !0;
                            break;
                        case "SHUANGFANGXIANG":
                            document.getElementById("shuangfangxiang").checked = !0;
                            break;
                        case "SANFANGXIANG":
                            document.getElementById("sanfangxiang").checked = !0
                    }
                } else {
                    n.find("#lieche").css({
                        display: "none"
                    }),
                        n.find("#diaoche").css({
                            display: "block"
                        }),
                        document.getElementById("lzButton").checked = !1,
                        document.getElementById("dlButton").checked = !1;
                    for (var c = 0; c < o.button.length; c++) switch (o.button[c]) {
                        case "LZBUTTON":
                            document.getElementById("lzButton").checked = !0;
                            break;
                        case "DLBUTTON":
                            document.getElementById("dlButton").checked = !0
                    }
                }
                var i = Model.elements[e].getRotatePoint(),
                    a = i.x + $("#designer_canvas").offset().left,
                    s = i.y + $("#designer_canvas").offset().top,
                    r = 35;
                $(window).width() - a < n.width() ? (a -= n.width(), a -= r) : a += r,
                    s = $("#designer_header").height();
                var n = $("#signalcfgpanel");
                n.css({
                    position: "absolute",
                    left: a + "px",
                    top: s + "px"
                }),
                    n.show();
                break;
            case "BUTTON":
                var n = $("#buttoncfgpanel"),
                    o = Model.getNodeByID(e);
                if ("BGBUTTON" !== o.buttonType && "YXBUTTON" !== o.buttonType) return;
                switch (n.hide(), $("#buttoncfgmsg").show(), n.find(".panel-title").text(o.name + "按钮参数配置"), n.find("#buttonname").val(o.name), n.find("#buttonthroat").val(o.throat), n.find("#qiannode").val(Model.getNameByID(Model.getIndexByID(o.qianNode))), n.find("#hounode").val(Model.getNameByID(Model.getIndexByID(o.houNode))), o.buttonType) {
                    case "BGBUTTON":
                        document.getElementById("bgbutton").checked = !0;
                        break;
                    case "LZBUTTON":
                        document.getElementById("lzbutton").checked = !0;
                        break;
                    case "DZBUTTON":
                        document.getElementById("dzbutton").checked = !0;
                        break;
                    case "YXBUTTON":
                        document.getElementById("yxbutton").checked = !0
                }
                var a = t.pageX,
                    s = t.pageY,
                    r = 25;
                $(window).width() - a < n.width() ? (a -= n.width(), a -= r) : a += r,
                    $(window).height() - $("#designer_header").height() - $("#designer_footer").height() - s < n.height() ? (s -= n.height(), s -= r) : s += r;
                var n = $("#buttoncfgpanel");
                n.css({
                    position: "absolute",
                    left: a + "px",
                    top: s + "px"
                }),
                    n.show();
                break;
            case "LIANXI":
                break;
            case "TUO_GUI_QI":
                break;
            case "QIN_XIAN":
                break;
            case "64D":
                break;
            case "TEXT":
                var n = $("#textcfgpanel"),
                    o = Model.getNodeByID(e);
                n.hide(),
                    n.find(".panel-title").text(o.name + "文字内容配置"),
                    n.find("#text").val(o.name),
                    n.find("#fontsize").val(o.fontStytle.size);
                var a = t.pageX,
                    s = t.pageY,
                    r = 18;
                $(window).width() - a < n.width() ? (a -= n.width(), a -= r) : a += r,
                    $(window).height() - $("#designer_footer").height() - s < n.height() ? (s -= n.height(), s -= r) : s += r,
                    n.css({
                        position: "absolute",
                        left: a + "px",
                        top: s + "px"
                    }),
                    n.show()
        }
    },
    showFixTipMessage: function (e, t) {
        var n = $("#fixtipmessage");
        n.find("span").text(e);
        var o = $(window).width() - .4 * $(window).width(),
            i = $("#designer_header").height() / 30;
        n.css({
            position: "absolute",
            left: o + "px",
            top: i + "px"
        }),
            n.hide(),
            n.fadeIn(300),
        t && setTimeout(function () {
                n.fadeOut(1e3)
            },
            2e3)
    },
    showFloatTipMessage: function (e, t) {
        var n = $("#autotipmessage");
        n.find("span").text(e),
            n.css({
                position: "absolute",
                left: t.x + "px",
                top: t.y + "px"
            }),
            n.fadeIn(100),
            setTimeout(function () {
                    n.fadeOut(400)
                },
                3e3)
    },
    deviceDataTableCFG: function (e) {
        function r() {
            $("#lsbdatacheck").find("td").unbind("dblclick").bind("dblclick",
                function (e) {
                    var t = $(this),
                        n = t.parent().attr("id"),
                        o = t.attr("property");
                    if ("spswitch" != n) {
                        if ("name" == o) return;
                        if (n = Model.getIndexByID(n), -1 == n) return
                    }
                    var i = t.css("padding"),
                        a = t.html();
                    if (t.css({
                            padding: "0px"
                        }), !t.find("input").length) {
                        var s = $("<input type='text' class='form-control'>");
                        s.css({
                            position: "inherit",
                            height: t.outerHeight() + "px",
                            width: t.outerWidth() + "px"
                        }),
                            s.val(t.text()),
                            t.empty(),
                            t.append(s),
                            s.select(),
                            s.bind("keyup",
                                function (e) {
                                    var a = e || window.event,
                                        s = a.keyCode;
                                    if (13 == s) {
                                        var r = $(this),
                                            l = r.val();
                                        if ("fhzhudaocha" == o || "fanghudaocha" == o || "ddzhudaocha" == o || "daidongdaocha" == o) t.html(l),
                                            t.css({
                                                padding: i
                                            });
                                        else {
                                            var h = Model.dataValidCheck(n, o, l),
                                                c = $("#lsbdatacheckmessage");
                                            0 == h.length ? (t.html(l), t.css({
                                                padding: i
                                            }), c.hide()) : (c.find("span").text(h), c.show())
                                        }
                                    }
                                }),
                            s.blur(function () {
                                t.css({
                                    padding: i
                                }),
                                    s.hide(),
                                    t.html(a)
                            }),
                            s.show()
                    }
                })
        }

        var n, t = Model.elements;
        $("#switchdata").find("tbody").empty(),
            $("#signaldata").find("tbody").empty(),
            $("#trackdata").find("tbody").empty(),
            $("#specialswitch").find("tbody").empty();
        for (var i = 0; i < t.length; i++)"SWITCH" == t[i].category ? (0 == $("#switchdata").find("thead").children().length && (n = "<tr>", n += "<td>名称</td><td>另一动</td><td>咽喉</td><td>所在区段</td><td>岔前节点</td><td>直股后节点</td><td>弯股后节点</td><td>交叉另一动</td>", n += "</tr>", $("#switchdata").find("thead").html(n)), n = "<tr id=" + t[i].id + ">", n += "<td property = 'name' >" + t[i].name + "</td>", n += "<td property = 'otherSwitch'>", n += -1 == t[i].otherSwitch ? t[i].otherSwitch : Model.getNameByID(Model.getIndexByID(t[i].otherSwitch)), n += "</td>", n += "<td property = 'throat'>" + t[i].throat + "</td>", n += "<td property = 'track'>" + t[i].track + "</td>", n += "<td property = 'qianNode'>" + Model.getNameByID(Model.getIndexByID(t[i].qianNode)) + "</td>", n += "<td property = 'zhiNode'>" + Model.getNameByID(Model.getIndexByID(t[i].zhiNode)) + "</td>", n += "<td property = 'wanNode'>" + Model.getNameByID(Model.getIndexByID(t[i].wanNode)) + "</td>", n += "<td property = 'otherdbcross'>", n += -1 == t[i].otherDoubleCrossover ? t[i].otherDoubleCrossover : Model.getNameByID(Model.getIndexByID(t[i].otherDoubleCrossover)), n += "</td>", n += "</tr>", $("#switchdata").find("tbody").append(n)) : "SIGNAL" == t[i].category ? (0 == $("#signaldata").find("thead").children().length && (n = "<tr>", n += "<td>名称</td><td>差/并置信号机</td><td>咽喉</td><td>前节点</td><td>后节点</td>", n += "</tr>", $("#signaldata").find("thead").html(n)), n = "<tr id=" + t[i].id + ">", n += "<td property = 'name' >" + t[i].name + "</td>", n += "<td property = 'otherSignal'>", n += -1 == t[i].otherSignal ? t[i].otherSignal : Model.getNameByID(Model.getIndexByID(t[i].otherSignal)), n += "</td>", n += "<td property = 'throat'>" + t[i].throat + "</td>", n += "<td property = 'qianNode'>" + Model.getNameByID(Model.getIndexByID(t[i].qianNode)) + "</td>", n += "<td property = 'houNode'>" + Model.getNameByID(Model.getIndexByID(t[i].houNode)) + "</td>", n += "</tr>", $("#signaldata").find("tbody").append(n)) : "TRACK" == t[i].category && (0 == $("#trackdata").find("thead").children().length && (n = "<tr>", n += "<td>名称</td><td>咽喉</td><td>前节点</td><td>后节点</td>", n += "</tr>", $("#trackdata").find("thead").html(n)), n = "<tr id=" + t[i].id + ">", n += "<td property = 'name' >" + t[i].name + "</td>", n += "<td property = 'throat'>" + t[i].throat + "</td>", n += "<td property = 'qianNode'>" + Model.getNameByID(Model.getIndexByID(t[i].qianNode)) + "</td>", n += "<td property = 'houNode'>" + Model.getNameByID(Model.getIndexByID(t[i].houNode)) + "</td>", n += "</tr>", $("#trackdata").find("tbody").append(n)),
            r();
        0 == $("#specialswitch").find("thead").children().length && (n = "<tr>", n += "<td>编号</td><td>主道岔</td><td>防护道岔</td><td>主道岔</td><td>带动道岔</td>", n += "</tr>", $("#specialswitch").find("thead").html(n));
        for (var a = 0; 20 > a; a++) n = "<tr id='spswitch'>",
            n += "<td property = 'index' >" + a + " </td>",
            n += "<td property = 'fhzhudaocha' > </td>",
            n += "<td property = 'fanghudaocha'> </td>",
            n += "<td property = 'ddzhudaocha'> </td>",
            n += "<td property = 'daidongdaocha'></td>",
            n += "</tr>",
            $("#specialswitch").find("tbody").append(n),
            r();
        var s = document.getElementById("spstable");
        for (a = 0; a < Model.fhSwitchTable.length; a++) s.rows[a].cells[1].innerText = Model.fhSwitchTable[a].zdc,
            s.rows[a].cells[2].innerText = Model.fhSwitchTable[a].fhdc;
        for (a = 0; a < Model.ddSwitchTable.length; a++) s.rows[a].cells[3].innerText = Model.ddSwitchTable[a].zdc,
            s.rows[a].cells[4].innerText = Model.ddSwitchTable[a].dddc
    },
    showDebugError: function (e) {
        if (0 != e.length) {
            var t = $("#lsbdatacheckerrorpanel");
            t.hide(),
                t.find("tbody").empty();
            for (var n = "",
                     o = 0; o < e.length; o++) n += "<tr class='danger' index=" + e[o].index + ">",
                n += "<td>" + e[o].tip + "</td>",
                n += "</tr>";
            t.find("tbody").append(n);
            var i = $(window).width() - 1.1 * t.width(),
                a = $("#designer_header").height();
            t.find("tr").unbind("dblclick").bind("dblclick",
                function () {
                    var e = $(this),
                        t = e.attr("index");
                    if (-1 != t) {
                        var i, n = $("#designer_layout").scrollTop(),
                            o = $("#designer_layout").scrollLeft();
                        if ("SWITCH" == Model.elements[t].category) i = Model.elements[t].component.chaJian[1];
                        else if ("SIGNAL" == Model.elements[t].category) i = Model.elements[t].component.base[1];
                        else if ("TRACK" == Model.elements[t].category) i = Model.elements[t].component.point[1];
                        else {
                            if ("BUTTON" != Model.elements[t].category) return;
                            i = Model.elements[t].component.point[0]
                        }
                        n = i.x,
                            o = i.y;
                        var a = .3 * $(window).width(),
                            s = .3 * $(window).height();
                        n += Designer.config.pageMargin.toScale(),
                            o += Designer.config.pageMargin.toScale(),
                            $("#designer_layout").scrollLeft(n - a),
                            $("#designer_layout").scrollTop(o - s)
                    }
                }),
                t.css({
                    position: "absolute",
                    left: i + "px",
                    top: a + "px"
                }),
                t.show()
        }
    },
    showLSBRouteTable: function () {
        if (0 != lsb.routateTable.length) {
            var e = $("#lsbrouteinfopanel");
            e.hide(),
                e.find("tbody").empty();
            for (var t = "",
                     n = 0; n < lsb.routateTable.length; n++) {
                t += "<tr class='success' index=" + n + ">",
                    t += "<td>";
                for (var o = 0; o < lsb.routateTable[n].shapes.length; o++) t += Model.getNameByID(lsb.routateTable[n].shapes[o].index) + "  ";
                t += "</td></tr>"
            }
            e.find("tbody").append(t);
            var i = $(window).width() - 1.1 * e.width(),
                a = $("#designer_header").height();
            e.find("tr").unbind("mouseenter").bind("mouseenter",
                function () {
                    var e = $(this),
                        t = e.attr("index"),
                        n = lsb.routateTable[t].shapes[0].index;
                    if (-1 != n) {
                        lsb.setPathStatu(t, "SELECTED_P");
                        var a, s, o = $("#designer_layout").scrollTop(),
                            i = $("#designer_layout").scrollLeft(),
                            n = lsb.routateTable[t].shapes[0].index;
                        if ("SWITCH" == Model.elements[n].category) a = Model.elements[n].component.chaJian[1];
                        else if ("SIGNAL" == Model.elements[n].category) a = Model.elements[n].component.base[1];
                        else if ("TRACK" == Model.elements[n].category) a = Model.elements[n].component.point[1];
                        else {
                            if ("BUTTON" != Model.elements[n].category) return;
                            a = Model.elements[n].component.point[0]
                        }
                        if (n = lsb.routateTable[t].shapes[lsb.routateTable[t].shapes.length - 1].index, "SWITCH" == Model.elements[n].category) s = Model.elements[n].component.chaJian[1];
                        else if ("SIGNAL" == Model.elements[n].category) s = Model.elements[n].component.base[1];
                        else if ("TRACK" == Model.elements[n].category) s = Model.elements[n].component.point[1];
                        else {
                            if ("BUTTON" != Model.elements[n].category) return;
                            s = Model.elements[n].component.point[0]
                        }
                        a.x < s.x ? (o = a.x, i = a.y) : (o = s.x, i = s.y);
                        var r = .2 * $(window).width(),
                            l = .2 * $(window).height();
                        o += Designer.config.pageMargin.toScale(),
                            i += Designer.config.pageMargin.toScale(),
                            $("#designer_layout").scrollLeft(o - r),
                            $("#designer_layout").scrollTop(i - l),
                            Designer.op.refreshElements()
                    }
                }),
                e.find("tr").unbind("mouseleave").bind("mouseleave",
                    function () {
                        var e = $(this),
                            t = e.attr("index");
                        -1 != t && (lsb.setPathStatu(t, "DEFAULT"), Designer.op.refreshElements())
                    }),
                e.css({
                    position: "absolute",
                    left: i + "px",
                    top: a + "px"
                }),
                e.show()
        }
    },
    showShapeTipInfo: function (e, t) {
        var n = $("#tipinfo");
        if (-1 == e) return void n.popover("destroy");
        n.popover("destroy");
        var o = Model.elements[e],
            i = "";
        if ("SWITCH" == o.category) i += "<strong>名称：</strong>",
            i += "<span>" + o.name + "<span></br>",
            i += "<strong>咽喉：</strong>",
            i += "<span>" + o.throat + "<span></br>",
            i += "<strong>所在区段：</strong>",
            i += "<span>" + o.track + "<span></br>",
            i += "<strong>岔尖节点：</strong>",
            i += -1 != o.qianNode ? "<span>" + Model.getNameByID(Model.getIndexByID(o.qianNode)) + "<span></br>" : "<span><span></br>",
            i += "<strong>直股节点：</strong>",
            i += -1 != o.zhiNode ? "<span>" + Model.getNameByID(Model.getIndexByID(o.zhiNode)) + "<span></br>" : "<span><span></br>",
            i += "<strong>弯股节点：</strong>",
            i += -1 != o.wanNode ? "<span>" + Model.getNameByID(Model.getIndexByID(o.wanNode)) + "<span></br>" : "<span><span></br>",
            i += "<strong>双动另一动：</strong>",
            i += -1 != o.otherSwitch ? "<span>" + Model.getNameByID(Model.getIndexByID(o.otherSwitch)) + "<span></br>" : "<span><span></br>",
            i += "<strong>交叉渡线另一动：</strong>",
            i += -1 != o.otherDoubleCrossover ? "<span>" + Model.getNameByID(Model.getIndexByID(o.otherDoubleCrossover)) + "<span></br>" : "<span><span></br>",
            i += "<strong>附属按钮：</strong>",
            i += -1 != o.extraButton.id ? "<span>" + Model.getNameByID(Model.getIndexByID(o.extraButton.id)) + "<span></br>" : "<span><span></br>";
        else if ("SIGNAL" == o.category) i += "<strong>名称：</strong>",
            i += "<span>" + o.name + "<span></br>",
            i += "<strong>咽喉：</strong>",
            i += "<span>" + o.throat + "<span></br>",
            i += "<strong>前节点：</strong>",
            i += -1 != o.qianNode ? "<span>" + Model.getNameByID(Model.getIndexByID(o.qianNode)) + "<span></br>" : "<span><span></br>",
            i += "<strong>后节点：</strong>",
            i += -1 != o.zhiNode ? "<span>" + Model.getNameByID(Model.getIndexByID(o.houNode)) + "<span></br>" : "<span><span></br>",
        o.type.match("DIAO") && (i += "<strong>差置信号机：</strong>", i += o.chaZhi ? "<span>" + Model.getNameByID(Model.getIndexByID(o.otherSignal)) + "<span></br>" : "<span><span></br>", i += "<strong>并置信号机：</strong>", i += o.bingZhi ? "<span>" + Model.getNameByID(Model.getIndexByID(o.otherSignal)) + "<span></br>" : "<span><span></br>");
        else if ("BUTTON" == o.category) i += "<strong>名称：</strong>",
            i += "<span>" + o.name + "<span></br>",
            i += "<strong>咽喉：</strong>",
            i += "<span>" + o.throat + "<span></br>",
            i += "<strong>前节点：</strong>",
            i += -1 != o.qianNode ? "<span>" + Model.getNameByID(Model.getIndexByID(o.qianNode)) + "<span></br>" : "<span><span></br>",
            i += "<strong>后节点：</strong>",
            i += -1 != o.zhiNode ? "<span>" + Model.getNameByID(Model.getIndexByID(o.houNode)) + "<span></br>" : "<span><span></br>",
            i += "<strong>按钮类型：</strong>",
            i += "BGBUTTON" == o.buttonType ? "<span>变更按钮<span></br>" : "YXBUTTON" == o.buttonType ? "<span>延续终端按钮<span></br>" : "<span>" + o.buttonType.toString() + "<span></br>";
        else {
            if ("TRACK" != o.category) return;
            i += "<strong>名称：</strong>",
                i += "<span>" + o.name + "<span></br>",
                i += "<strong>咽喉：</strong>",
                i += "<span>" + o.throat + "<span></br>",
                i += "<strong>前节点：</strong>",
                i += -1 != o.qianNode ? "<span>" + Model.getNameByID(Model.getIndexByID(o.qianNode)) + "<span></br>" : "<span><span></br>",
                i += "<strong>后节点：</strong>",
                i += -1 != o.zhiNode ? "<span>" + Model.getNameByID(Model.getIndexByID(o.houNode)) + "<span></br>" : "<span><span></br>",
                i += "<strong>区段类型：</strong>",
                i += "GD" == o.trackType ? "<span>股道<span></br>" : "WCQD" == o.trackType ? "<span>无岔区段<span></br>" : "DCQD" == o.trackType ? "<span>道岔区段<span></br>" : "<span><span></br>"
        }
        n.css({
            position: "absolute",
            left: t.pageX + 18 + "px",
            top: t.pageY + "px"
        }),
            n.find("popover-content").empty(),
            n.popover({
                placement: "right",
                html: "true",
                content: "<div>" + i + "</div>",
                animation: !1
            }),
            n.popover("show")
    }
};